
#ifndef __InterfaceBase_H
#define __InterfaceBase_H

// #include "com_buf.h"
#include <cstdint>

#ifndef RET_SUCCESS
	#define RET_SUCCESS      1
#endif

#ifndef RET_FAIL
	#define RET_FAIL		-1
#endif
 //---------- 硬件板号，MainUnit按板号进行命令分发。如系统复位，文件操作
 enum boardID
 {
 	 BoardID_PCUnit		 	 = 0x0,      //PC主机，andriod主机
	 BoardID_MainUnit		 = 0x1, 	 //主控板 
	 BoardID_DrySpiceUnit 	 = 0x2, 	 //干料板
	 BoardID_LiquidSpiceUnit = 0x3, 	 //湿料板
	 BoardID_WeightSpiceUnit = 0x4, 	 //称重板
	 BoardID_OilBox 		 = 0x5, 	 //猪油板
	 
	 BoardID_Max		 	 = BoardID_WeightSpiceUnit, 	 //
 };
 
 //---------- 硬件主机模块ID.上位机正常工作时的命令，一般都是发给模块。如倾锅电机到0位

//all Units
#define  UnitsModID_Vir			 	0xf 	 //虚拟模块。如文件传送
#define  UnitsModID_Misc	 	 	0x0 	 //Misc模块，如延时

//mainUnit
#define  MainModID_RollPot		 	0x1 	 //转锅模块
#define  MainModID_leanPot		 	0x2 	 //倾斜锅模块
#define  MainModID_InfraTemp	 	0x3 	 //红外测温模块
#define  MainModID_Oil	 		 	0x4 	 //食用油模块
#define  MainModID_oilHeatStrip	 	0x5 	 //加热条模块
#define  MainModID_CoilFan	 		0x6 	 //加热盘风扇模块
#define  MainModID_Water	 	 	0x7 	 //给水模块
#define  MainModID_HeatContrller	0x8 	 //线圈加热控制模块
#define  MainModID_StarchMix	 	0x9 	 //水淀粉搅拌模块
#define  MainModID_StarchSpice	 	0xa 	 //水淀调料抽取模块
#define  MainModID_Weight		 	0xb 	 //称重模块
#define  MainModID_VentilateFan		0xc 	 //机器通风风扇
#define  MainModID_Drinking_Water	0xe 	 //饮用水模块
#define  MainModID_StarchClean      0x10      //水淀粉管道清洗
#define  MainModID_MachineInfo      0x11    //eeprom 参数配置模块 写入
#define  MainModID_Read_MachineInfo 0x12    //eeprom 参数配置模块 读取

#define  MainModID_Valve1 			0x13  	  //电磁阀1  对应投洗锅水，本身阀就是独立控制
#define  MainModID_Valve2 			0x14      //电磁阀2 
#define  MainModID_Valve3 			0x15      //电磁阀3 
#define  MainModID_Valve4 			0x16      //电磁阀4 
#define  MainModID_Unit_Valve 		0x17      //电磁阀组合控制 ,用于清洗相关

//DrySpiceUnit
#define  DrySpiceModID_Spice1	 	0x1 	 //干粉调料模块1
#define  DrySpiceModID_Spice2	 	0x2 	 //干粉调料模块2
#define  DrySpiceModID_Spice3	 	0x3 	 //干粉调料模块3
#define  DrySpiceModID_Spice4	 	0x4 	 //干粉调料模块4	 
#define  DrySpiceModID_Spice5	 	0x5 	 //干粉调料模块5
#define  DrySpiceModID_Fan	 		0x6 	 //风扇模块
#define  DrySpiceModID_Door	 		0x7  	 //干料盒门

#define BTKCP_DISABLE_WEIGHT_BOARD 0x4E //禁止称重板，如果是max建议发送该指令。

//LiquidSpice
#define  LiquidSpiceModID_Spice1	 0x1 	 //液体调料模块1
#define  LiquidSpiceModID_Spice2	 0x2 	 //液体调料模块2 
#define  LiquidSpiceModID_Spice3	 0x3 	 //液体调料模块3
#define  LiquidSpiceModID_Spice4	 0x4 	 //液体调料模块4 
#define  LiquidSpiceModID_Spice5	 0x5 	 //液体调料模块5
#define  LiquidSpiceModID_Spice6	 0x6 	 //液体调料模块6 
#define  LiquidSpiceModID_Spice7	 0x7 	 //液体调料模块7
#define  LiquidSpiceModID_Spice8	 0x8 	 //液体调料模块8 

#define  LiquidSpiceModID_Oyster	 		0x9 	 //蚝油调料模块 

//----------------- 零件ID ,通信协议，地址(模块、组件)。上位机在测试时才会使用零件ID。如某个电机走1秒
 enum ComponentPartID
 {
	 PartID_Vir				= 0x0, 	 //虚拟零件。
	 
	 PartID_StepMotor		= 0x1, 	 //步进电机
	 PartID_EncoderMotor	= 0x2, 	 //有编码器电机
	 PartID_FreeMotor		= 0x3, 	 //无编码器电机
	 
	 PartID_Pumb			= 0x4, 	 //泵。同继电器相比，有方向、速度控制，和无编码电机类似
	 PartID_Relay			= 0x5, 	 //继电器。继电器控制的无方向、无速度电机也可归入这一类
	 
	 PartID_Optocoupler		= 0x6, 	 //光耦
	 PartID_CheckTemp		= 0x7, 	 //测温元件
	 PartID_controlTempPower= 0x8, 	 //温控、功率控制元件

	 PartID_Undefine  		= 0xff,		//未定义部件 
 };


enum ComponentUpdatePartID
{
	UpdatePartID_Group1			= 0x1,   
	UpdatePartID_Group2			= 0x2,  
	UpdatePartID_Group3			= 0x3,   
	UpdatePartID_Group4			= 0x4,   
	UpdatePartID_Group5			= 0x5,  
	UpdatePartID_Group6			= 0x6,  
	UpdatePartID_Group7			= 0x7,   
};

// 液料板状态数据
typedef struct 
{//要根据实际ID对应
	uint8_t liu1_dir;
	uint8_t liq1_speed;
	uint8_t liu2_dir;
	uint8_t liq2_speed;
	uint8_t liu3_dir;
	uint8_t liq3_speed;
	uint8_t liu4_dir;
	uint8_t liq4_speed;
	uint8_t liu5_dir;
	uint8_t liq5_speed;
	uint8_t liu6_dir;
	uint8_t liq6_speed;
	uint8_t liu7_dir; 
	uint8_t liq7_speed;
}__attribute__((packed)) UpdateLiquidStatus;


// struct UpdateHeatStatus
// {
// 	uint16_t box_temper;	// 机器温度
// 	uint16_t coil_temper;	// 线盘温度
// 	uint16_t set_power;		// 设置功率
// 	uint16_t output_power;	// 输出功率
// 	uint16_t bus_voltage;	// 母线电压
// 	uint16_t bus_current;	// 母线电流
// 	uint16_t out_voltage;	// 输出电压
// 	uint16_t out_current;	// 输出电流
// 	uint16_t bus_frequency; // 频率
// 	uint16_t temp_coil;	  // 线盘温度限制
// 	uint16_t temp_heater; // 机芯温度限制
// 	uint8_t offline;		// 错误码
// 	uint8_t factory_id;
// 	uint8_t err_code;		// 错误码
// };

//机芯状态拆分问两个包
typedef struct  
{
	uint16_t box_temper;	// 机器温度
	uint16_t coil_temper;	// 线盘温度
	uint16_t set_power;		// 设置功率  单位 10W
	uint16_t output_power;	// 输出功率  单位 10W
	uint16_t bus_voltage;	// 母线电压
	uint16_t bus_current;	// 母线电流
	uint16_t out_voltage;	// 输出电压
	uint16_t out_current;	// 输出电流
}__attribute__((packed)) HeatStatus1;

typedef struct
{
	uint16_t bus_frequency; // 频率
	uint16_t temp_coil;	  // 线盘温度限制
	uint16_t temp_heater; // 机芯温度限制
	uint8_t offline;		// 错误码
	uint8_t factory_id;
	uint8_t err_code;		// 错误码
	uint16_t high_hz_i_limit;	// 高频电流限制值
	uint16_t high_hz_i_max; 	// 高频电流峰值
	uint16_t i_phase;	  		// 电流相位值
}__attribute__((packed)) HeatStatus2;


typedef struct  
{
	uint32_t hall; // 电机霍尔数
	uint16_t voltage; // 电机电压
	uint16_t current; // 电机电流
	uint8_t speed; // 电机速度 
	uint8_t direction; // 电机方向
	uint8_t error_code; //驱动器故障码
	uint8_t zero_sensor; // 原点传感器
	uint8_t offline; // 0正常1掉线
	uint8_t dev_id; // 电机ID
}__attribute__((packed)) MotorStatus;



typedef struct 
{
	uint16_t ir_temper;  // 温度
	uint16_t ir_filter_temper;  // 过滤温度
	uint8_t ir_factory_id;
	uint8_t ir_offline; //是否掉线
	uint8_t ir_timeout_count_interval; // 两次查询间隔通信超时次数
}__attribute__((packed)) IrAndOtherStatus;

typedef struct 
{
	uint8_t mix_speed;  
	uint8_t mix_dir;  	
    uint8_t mix_error; 
	uint8_t sta_pump_speed;
	uint8_t sta_pump_dir;
    uint8_t fan_mode;  // 风扇类型
	uint8_t fan_speed[4];  // 速度
	uint8_t fan_error;
    uint8_t vaule1_status;  // 阀1状态，洗锅水阀
	uint8_t vaule2_status;  // 阀2状态，水盒进水阀
	uint8_t vaule3_status;  // 阀3状态，水淀粉两位三通阀 1
	uint8_t vaule4_status;  // 阀3状态，水淀粉两位三通阀 1
	uint8_t water_pump_speed; // 小水泵状态
}__attribute__((packed)) VauleFanStarchStatus;

//干料板状态数据
typedef struct  
{
	uint8_t open_sensor; 
	uint8_t close_sensor;  
	uint8_t door_status; // 0 未知 1开门 2关门
	uint8_t door_error;
}__attribute__((packed)) UpdateDoorStatus;

// 调料电机
typedef struct 
{
	uint32_t hall; 
	uint8_t speed;  
	uint8_t dir; 
	uint8_t error;
	uint8_t dev_id;
}__attribute__((packed)) UpdateDryStatus;

typedef struct 
{
	float zero_weight;  // 秤去皮基值
	float calib_k;   	// 秤校准曲线K
	float calib_b;   	// 秤校准曲线B
	uint8_t dev_id;
}__attribute__((packed)) UpdateWeightCalibStatus;





 // ---------------------------------协议ID--------------------------------
 #define PROTOCAL_TEMPERATURE		0x80
 #define PROTOCAL_UPDATE_STATUS		0x81

 #define PROTOCAL_EVENT				0x10	//事件
	#define EVENT_BOX_STATUS		0x1		//调料盒状态
	#define EVENT_MCU_TEMP			0x2		//mcu 温度

	#define EVENT_ROLLPOT_SPEED		0x4		//转锅转速
	#define EVENT_UPDATE_PERCENT	0x5		//下位机升级百分比
	
	#define EVENT_WEIGHT_RAW_DATA	0x6 	//称重原始数据

	#define EVENT_TEMP_CTRL_STATUS	0x7 	//温控状态数据	

	#define EVENT_MOT_CURRENT		0x10	//马达电流	
	#define EVENT_MOT_VOLTAGE 		0x11	//马达电压						
	#define EVENT_MOT_POWER 		0x12	//马达功率						
	#define EVENT_MOT_SPEED 		0x13	//马达转速						

#endif

